package xquery;
import java.util.*;

import org.w3c.dom.*;
public abstract class XQExpression {
	abstract public XPathData eval(XQContext context, ArrayList<Node> currentNodeList);
	public ArrayList<Node> getDescendants(XQContext context, ArrayList<Node> currentNodeList)
	{
		ArrayList<Node> newCurrentNodeList = new ArrayList<Node>();
		Queue<Node> queue = new LinkedList<Node>();
		NodeList children;
		Node current = null;
		for(Node node: currentNodeList)
		{
			queue.add(node);
			while(!queue.isEmpty())
			{
				current = queue.remove();
				if(current!= null)
				{
					newCurrentNodeList.add(current);
					children = current.getChildNodes();
					for(int i=0;i<children.getLength();i++)
					{
						queue.add(children.item(i));
					}
				}
			}
		}
		return newCurrentNodeList;
	}
}
